<?php
/**
 * Notes:
 * User: Administrator
 * Date: 2020/9/28
 * Time: 13:34
 * ${PARAM_DOC}
 * @return ${TYPE_HINT}
 * ${THROWS_DOC}
 */

namespace App\Http\model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Dotenv\Exception;

class CheckRefundStatus extends Model
{
    /**
     * 【查找退款订单的状态】
     * @param $OrderID erp请求的参数订单号
     */
    public function searchOrderStatusModel($OrderID)
    {
        $orderStatus = DB::table('orderdetail')
            ->select(
                'OIcode',
                'Status',
                'orStatus'
            )
            ->where('OIcode', $OrderID)
            ->first();
//        dd($orderStatus);
        $orderStatus = json_decode(json_encode($orderStatus), true);
//        [50, 51, 52, 59, 60, 61, 62, 69, 70, 71, 72, 79]

        if ($orderStatus['Status'] == 50) {
            return 'JH_01';//'JH_01'买家已经申请退款等待卖家同意
        } elseif ($orderStatus['Status'] == 59) {
            return 'JH_06';//'JH_06';//卖家已退款
        } elseif ($orderStatus['Status'] == 52) {
            return 'JH_04';//卖家拒绝退款=JH_04
        } elseif ($orderStatus['Status'] !== 50
            || $orderStatus['Status'] !== 51
            || $orderStatus['Status'] !== 52
            || $orderStatus['Status'] !== 59
            || $orderStatus['Status'] !== 60
            || $orderStatus['Status'] !== 61
            || $orderStatus['Status'] !== 62
            || $orderStatus['Status'] !== 69
            || $orderStatus['Status'] !== 70
            || $orderStatus['Status'] !== 72
            || $orderStatus['Status'] !== 71
            || $orderStatus['Status'] !== 79) {
            return 'JH_07';//没有退款
        }

//        return $this->orderStatus($orderStatus);
    }

    /**
     * 【退款返回数据】
     * author 孙凯
     * time   20200923 17:32
     * @param $CheckRefundStatus
     * @return \Illuminate\Http\JsonResponse
     */
    public function CheckRefundStatusModel($CheckRefundStatus)
    {
        if ($CheckRefundStatus == 'JH_01') {
            return response()->json(['refundStatus' => "JH_01", 'refundStatusdescription' => '买家已经申请退款等待卖家同意', 'code' => '10000', 'message' => "SUCCESS", "submessage" => "买家已经申请退款等待卖家同意"]);
        } elseif ($CheckRefundStatus == 'JH_06') {
            return response()->json(['refundStatus' => "JH_06", 'refundStatusdescription' => '退款成功', 'code' => '10000', 'message' => "SUCCESS", "submessage" => "退款成功"]);
        } elseif ($CheckRefundStatus == 'JH_04') {
            return response()->json(['refundStatus' => "JH_04", 'refundStatusdescription' => '买家已经申请退款等待卖家同意', 'code' => '10000', 'message' => "SUCCESS", "submessage" => "卖家拒绝退款"]);
        } elseif ($CheckRefundStatus == 'JH_07') {//没有退款
            return response()->json(['refundStatus' => "JH_07", 'refundStatusdescription' => '没有退款', 'code' => '10000', 'message' => "SUCCESS", "submessage" => "没有退款"]);
        } else {
            return response()->json(['refundStatus' => "JH_99", 'refundStatusdescription' => '其他', 'code' => '10000', 'message' => "SUCCESS", "submessage" => "其他"]);
        }
    }
}